{extend name="_container/add"}

{block name="content"}
{if $r.id}
<input type="hidden" name="id" value="{$r.id}">
{/if}
<input type="hidden" name="table_id" value="{:input('table_id')}">
<div class="layui-form-item">
    <label class="layui-form-label required">中文名<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="comment" id="info_comment" class="layui-input modelform_comment"
               lay-verify="required" value="{$r?$r['comment']:''}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label required">英文名<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="name" id="info_name" class="layui-input modelform_name"
               lay-verify="required" value="{$r?$r['name']:''}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label required">类型</label>
    <div class="layui-input-inline">
        <select name="type" class="select2" lay-ignore id="field_type" style="min-width: 110px;" lay-verify="required">
            <option value="varchar">varchar</option>
            <option value="int">int</option>
            <option value="tinyint">tinyint</option>
            <option value="double">double</option>
            <option value="char">char</option>
            <option value="text">text</option>
            <option value="longtext">longtext</option>
            <option value="json">json</option>
        </select>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label ">长度<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="length" id="field_length" class="layui-input modelform_name"
               value="{$r?$r['length']:'400'}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label required">允许为空<span></span></label>
    <div class="layui-input-inline">
        <input type="radio" placeholder="" name="is_null" id="info_is_null1" class="layui-input modelform_name"
               value="1" checked style="" autocomplete="off" title="是">


        <input type="radio" placeholder="" name="is_null" id="info_is_null0" class="layui-input modelform_name"
               value="0"  style="" autocomplete="off" title="否">


        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label ">默认值<span></span></label>
    <div class="layui-input-inline">
        <input type="text" placeholder="" name="default" id="field_default" class="layui-input modelform_name"
                value="{$r?$r['default']:''}" style="" autocomplete="off">
        <div class="description"></div>
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
</div>


{/block}
{block name="js"}
<script>
    function save_form3(obj) {
        save_form2(obj);
        return false;
    }
</script>

<script>
    let pre = "{:env('database.prefix')}";
    $('#info_comment').blur(
        function (obj) {
            let word = obj.target.value;
            if (word) {
                $.get('/auto/util/getEnglishWithType?word=' + word, (data) => {
                    let res = data.result.res;
                    let type = data.result.type;
                    $('#info_name').val(res);
                    $('#field_type').val(type).select2();
                    switch (type) {
                        case 'varchar':
                            $('#field_length').val(400);
                            $('#field_default').val('');
                            break;
                        case 'int':
                            $('#field_length').val(11);
                            $('#field_default').val('0');
                            break;
                        case 'tinyint':
                            $('#field_length').val(1);
                            $('#field_default').val(0);
                            break;
                        case 'double':
                            $('#field_length').val('10,2');
                            $('#field_default').val('0.00');
                            break;
                        case 'text':
                            $('#field_length').val('');
                            $('#field_default').val('');
                            break;
                        case 'longtext':
                            $('#field_length').val('');
                            $('#field_default').val('');
                            break;
                        case 'char':
                            $('#field_length').val('32');
                            $('#field_default').val('');
                            break;
                        case 'json':
                            $('#field_length').val('');
                            $('#field_default').val('');
                            break;
                    }
                })
            }
        }
    )
</script>


<script>
    $('#field_type').change(
        () => {
            let type = $("#field_type").val();
            switch (type) {
                case 'varchar':
                    $('#field_length').val(400);
                    $('#field_default').val('');
                    break;
                case 'int':
                    $('#field_length').val(11);
                    $('#field_default').val('0');
                    break;
                case 'tinyint':
                    $('#field_length').val(1);
                    $('#field_default').val(0);
                    break;
                case 'double':
                    $('#field_length').val('10,2');
                    $('#field_default').val('0.00');
                    break;
                case 'text':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
                case 'longtext':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
                case 'char':
                    $('#field_length').val('32');
                    $('#field_default').val('');
                    break;
                case 'json':
                    $('#field_length').val('');
                    $('#field_default').val('');
                    break;
            }
        }
    )
</script>
{/block}

{/extend}
